package com.lzy.web.facade.mq;

import com.alibaba.fastjson.JSON;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.amqp.rabbit.support.CorrelationData;
import org.springframework.stereotype.Service;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: ellengou
 * Date: 2017-12-13
 * Time: PM 1:54
 */
@Service
public class RabbitmqConfirmCallBackListener implements RabbitTemplate.ConfirmCallback {

    private static Logger logger = LoggerFactory.getLogger(RabbitmqConfirmCallBackListener.class);

    @Override
    public void confirm(CorrelationData correlationData, boolean ack, String cause) {
        try {
            if (!ack) {
                logger.info("send message failed: " + cause + correlationData.toString());
            } else {//发送成功，更新消息日志表数据
                logger.info("update message send status ===" + JSON.toJSONString("confirm--:correlationData:" + correlationData + ",ack:" + ack + ",cause:" + cause));
            }

        } catch (Exception e) {
            logger.error("message confirm exception ：" + e);
        }
    }
}